<?php

namespace app\common\job;

use app\common\library\EsignServer;
use think\queue\Job;

/**
 * create by PhpStorm 2025/8/20 10:44
 * szyc.com app\common\job@Esign
 * 行止之行 <xingzhi8711@gmail.com>
 * E签宝签署
 */
class Esign
{
    public function fire(Job $job,$data)
    {
        setLog(__METHOD__,"第".$job->attempts()."轮任务开始");
        $list=\app\admin\model\Esign::where("status","wait")->whereNotNull('follow_id')->select();
        clearLog(__METHOD__);
        foreach ($list as $k=>$v){
            setLog(__METHOD__,"查询签署： \t".$v['name']." \t".$v['phone']." \t".$v['follow_id']." \t".$v['status']);
            $esignServer=new EsignServer($v);
            $status=$esignServer->checkVerify($v['follow_id']);
            setLog(__METHOD__,"新状态 \t".$status);
            if ($status=="签署中"){
                $v->status="wait";
            }elseif($status=="完成"){
                $v->status="over";
            }else{
                $v->status="fail";
            }
            $v->save();
        }
        setLog(__METHOD__,"第".$job->attempts()."轮任务结束");
        $job->release('7200');
    }
}